import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestIp {

    public static void main(String[] args) {
        InetAddress local;
        InetAddress remote;
        try {
            local = InetAddress.getLocalHost();// 获取本地主机的地址
            System.out.println(local.getHostAddress());  // 获取字符串格式的原始IP地址

            remote = InetAddress.getByName("www.sohu.com");// 获取给定主机名的IP地址
            System.out.println(remote.getHostAddress());


        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

}
